package SquarePackage;

import static org.junit.Assert.*;

import java.util.HashSet;
import java.util.Set;

import org.junit.Before;
import org.junit.Test;

public class TeleportableSquareTest {
	private TeleportableSquare square5;
	private TeleportableSquare square4;
	private TeleportableSquare square3;
	private TeleportableSquare square2;
	private TeleportableSquare square1;
	@Before
	public void setUp() throws Exception {
		
		square5 = new NormalSquare();
		square4 = new NormalSquare();
		square1 = new NormalSquare();
		square2 = new NormalSquare();
		square3 = new TransparentSquare();
		Set<TeleportableSquare> destinations = new HashSet<TeleportableSquare>();
		destinations.add(square2);
		destinations.add(square3);
		destinations.add(square4);
		destinations.add(square5);
		square1.setDestinations(destinations);
	}

	@Test
	public void testAddDestination() {
		square5.addDestination(square1);
		square5.addDestination(square2);
		square5.addDestination(square3);
		square5.addDestination(square4);
		square2.addDestination(square1);
		square2.addDestination(square3);
		square2.addDestination(square4);
		square2.addDestination(square5);
		square3.addDestination(square2);
		square4.addDestination(square3);
		square3.addDestination(square4);
		square3.addDestination(square5);
		square3.addDestination(square1);
		square4.addDestination(square2);
		square4.addDestination(square1);
		square1.addDestination(square4);
		square4.addDestination(square5);
		square1.addDestination(square2);
		square1.addDestination(square3);
		square1.addDestination(square4);
		square1.addDestination(square5);
		square1.addDestination(square5);
		assertTrue((square1.getReachableSquares().size() + square5.getReachableSquares().size() + square4.getReachableSquares().size()+square3.getReachableSquares().size()+square2.getReachableSquares().size())==20);
	}
	@Test	(expected = AssertionError.class)
	public void testAddDestinationErrorCase(){
		square5.addDestination(square5);
	}

	@Test	
	public void testSetDestinations() {
		assertEquals(square1.getReachableSquares().size(),4,0);
	}

	@Test
	public void testCanTeleportTo() {
		assertTrue(square1.canTeleportTo(square2));
		assertTrue(square1.canTeleportTo(square5));
		assertTrue(square1.canTeleportTo(square4));
		assertTrue(square1.canTeleportTo(square3));
	}

	@Test
	public void testTeleport() {
		Set<TeleportableSquare> tempSet = new HashSet<TeleportableSquare>();
		while(tempSet.size()<4){
			tempSet.add(square1.teleport());
		}
		assertEquals(4, tempSet.size(),0);
	}

	@Test
	public void testHasTeleportationEnabled() {
		assertTrue(square1.hasTeleportationEnabled());
	}
}
